i2crepeater 2.2.0
Loading...
Searching...
No Matches
i2crepeater.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
27
28#ifndef I2CREPEATER_H
29#define I2CREPEATER_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52
58
63
68
74#define I2CREPEATER_DEVICE_ADDRESS 0x00
75 // i2crepeater_set
77
82
87
92#define I2CREPEATER_MAP_MIKROBUS( cfg, mikrobus ) \
93 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
94 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
95 cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST );
96 // i2crepeater_map // i2crepeater
99
104typedef struct
105{
106 // Output pins
107 digital_out_t en;
108
109 // Modules
110 i2c_master_t i2c;
111
112 // I2C slave address
114
116
121typedef struct
122{
123 pin_name_t scl;
124 pin_name_t sda;
125
126 pin_name_t en;
127
128 uint32_t i2c_speed;
129 uint8_t i2c_address;
130
132
143
149
160
175
185
195
206err_t i2crepeater_set_i2c_address ( i2crepeater_t *ctx, uint8_t slave_addr );
207
219err_t i2crepeater_i2c_write ( i2crepeater_t *ctx, uint8_t *data_in, uint16_t len );
220
232err_t i2crepeater_i2c_read ( i2crepeater_t *ctx, uint8_t *data_out, uint16_t len );
233
247err_t i2crepeater_i2c_write_then_read ( i2crepeater_t *ctx, uint8_t *data_in, uint16_t in_len,
248 uint8_t *data_out, uint8_t out_len );
249
262err_t i2crepeater_i2c_write_reg ( i2crepeater_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
263
276err_t i2crepeater_i2c_read_reg ( i2crepeater_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
277
278#ifdef __cplusplus
279}
280#endif
281#endif // I2CREPEATER_H
282 // i2crepeater
284
285// ------------------------------------------------------------------------ END
err_t i2crepeater_init(i2crepeater_t *ctx, i2crepeater_cfg_t *cfg)
I2C Repeater initialization function.
err_t i2crepeater_i2c_write(i2crepeater_t *ctx, uint8_t *data_in, uint16_t len)
I2C Repeater write function.
err_t i2crepeater_i2c_read(i2crepeater_t *ctx, uint8_t *data_out, uint16_t len)
I2C Repeater read function.
err_t i2crepeater_i2c_write_reg(i2crepeater_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
I2C Repeater write register function.
void i2crepeater_cfg_setup(i2crepeater_cfg_t *cfg)
I2C Repeater configuration object setup function.
err_t i2crepeater_i2c_read_reg(i2crepeater_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
I2C Repeater read register function.
err_t i2crepeater_set_i2c_address(i2crepeater_t *ctx, uint8_t slave_addr)
I2C Repeater set I2C address function.
void i2crepeater_disable_device(i2crepeater_t *ctx)
I2C Repeater disable device function.
void i2crepeater_enable_device(i2crepeater_t *ctx)
I2C Repeater enable device function.
err_t i2crepeater_i2c_write_then_read(i2crepeater_t *ctx, uint8_t *data_in, uint16_t in_len, uint8_t *data_out, uint8_t out_len)
I2C Repeater write then read function.
i2crepeater_return_value_t
I2C Repeater Click return value data.
Definition i2crepeater.h:138
@ I2CREPEATER_ERROR
Definition i2crepeater.h:140
@ I2CREPEATER_OK
Definition i2crepeater.h:139
I2C Repeater Click configuration object.
Definition i2crepeater.h:122
uint32_t i2c_speed
Definition i2crepeater.h:128
pin_name_t scl
Definition i2crepeater.h:123
pin_name_t en
Definition i2crepeater.h:126
pin_name_t sda
Definition i2crepeater.h:124
uint8_t i2c_address
Definition i2crepeater.h:129
I2C Repeater Click context object.
Definition i2crepeater.h:105
i2c_master_t i2c
Definition i2crepeater.h:110
digital_out_t en
Definition i2crepeater.h:107
uint8_t slave_address
Definition i2crepeater.h:113